package com.sdb.department.service.impl;

import java.util.List;
import com.sdb.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sdb.department.mapper.TdDepartmentMapper;
import com.sdb.department.domain.TdDepartment;
import com.sdb.department.service.ITdDepartmentService;

/**
 * 科室信息Service业务层处理
 * 
 * @author yyh
 * @date 2024-12-30
 */
@Service
public class TdDepartmentServiceImpl implements ITdDepartmentService 
{
    @Autowired
    private TdDepartmentMapper tdDepartmentMapper;


    /**
     * 查询科室信息
     * 
     * @param departmentId 科室信息主键
     * @return 科室信息
     */
    @Override
    public TdDepartment selectTdDepartmentByDepartmentId(Long departmentId)
    {
        return tdDepartmentMapper.selectTdDepartmentByDepartmentId(departmentId);
    }

    /**
     * 查询科室信息列表
     * 
     * @param tdDepartment 科室信息
     * @return 科室信息
     */
    @Override
    public List<TdDepartment> selectTdDepartmentList(TdDepartment tdDepartment)
    {
        return tdDepartmentMapper.selectTdDepartmentList(tdDepartment);
    }

    /**
     * 新增科室信息
     * 
     * @param tdDepartment 科室信息
     * @return 结果
     */
    @Override
    public int insertTdDepartment(TdDepartment tdDepartment)
    {
        tdDepartment.setCreateTime(DateUtils.getNowDate());
        // 判断是否有重复
        Integer count = tdDepartmentMapper.selectbyId(tdDepartment.getDepartmentId());
        if (count != null && count > 0) {
            // 如果存在相同的departmentId，抛出异常或返回错误信息
            throw new RuntimeException("该科室编码已存在");
        }
        // 如果不存在相同的departmentId，继续插入操作
        tdDepartmentMapper.insertDict(tdDepartment);
        return tdDepartmentMapper.insertTdDepartment(tdDepartment);
    }

    /**
     * 修改科室信息
     * 
     * @param tdDepartment 科室信息
     * @return 结果
     */
    @Override
    public int updateTdDepartment(TdDepartment tdDepartment)
    {
        return tdDepartmentMapper.updateTdDepartment(tdDepartment);
    }

    /**
     * 批量删除科室信息
     * 
     * @param departmentIds 需要删除的科室信息主键
     * @return 结果
     */
    @Override
    public int deleteTdDepartmentByDepartmentIds(Long[] departmentIds)
    {
        tdDepartmentMapper.deleteDict(departmentIds);
        return tdDepartmentMapper.deleteTdDepartmentByDepartmentIds(departmentIds);
    }

    /**
     * 删除科室信息信息
     * 
     * @param departmentId 科室信息主键
     * @return 结果
     */
    @Override
    public int deleteTdDepartmentByDepartmentId(Long departmentId)
    {
        return tdDepartmentMapper.deleteTdDepartmentByDepartmentId(departmentId);
    }
}
